package com.zl.logic
{
	import com.zl.bean.DgTypeBean;
	import com.zl.bean.FactorBean;
	import com.zl.enums.*;
	import common.CommonData;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.ResultEvent;
	
	[Event(name="levelComplete", type="flash.events.Event")]
	
	public class InitCommonData extends EventDispatcher
	{
		public function InitCommonData()
		{
		}
		
		//初始化第二步中的水平数列表
		public function initLevelList():void{
			if(CommonData.getInstance().levelList.length == 0){
				CommonData.getInstance().levelList.addItem("请选择");
				CommonData.getInstance().levelList.addItem("2");
				CommonData.getInstance().levelList.addItem("3");
				CommonData.getInstance().levelList.addItem("4");
			}
			dispatchEvent(new Event("levelComplete"));
		}
		
		//初始化第一步中的DataGrid的字段
		public function initDgTypeList(type:String):void{
			var bean:DgTypeBean ;
			if(type == "" || type == HeModuleType.HE.field){//"he"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemHe:HeModuleType in HeModuleType.HeModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemHe.text;
					bean.dataField = itemHe.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == HeModuleType.HF.field){//"hf"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemHf:HeModuleType in HeModuleType.HfModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemHf.text;
					bean.dataField = itemHf.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}
			/*else if(type == FModuleType.FE.field){//"fe"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemFe:FModuleType in FModuleType.FeModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemFe.text;
					bean.dataField = itemFe.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == FModuleType.FF.field){//"ff"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemFF:FModuleType in FModuleType.FfModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemFF.text;
					bean.dataField = itemFF.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}*/
			else if(type == PckModuleType.PCKE.field){//"pcke"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemPCKE:PckModuleType in PckModuleType.PckeModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemPCKE.text;
					bean.dataField = itemPCKE.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == PckModuleType.PCKF.field){//"pckf"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemPCKF:PckModuleType in PckModuleType.PckfModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemPCKF.text;
					bean.dataField = itemPCKF.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}
			/*else if(type == GModuleType.GE.field){//"ge"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemGE:GModuleType in GModuleType.GeModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemGE.text;
					bean.dataField = itemGE.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == GModuleType.GF.field){//"gf"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemGF:GModuleType in GModuleType.GfModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemGF.text;
					bean.dataField = itemGF.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}*/
			else if(type == MModuleType.ME.field){//"me"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemME:MModuleType in MModuleType.MeModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemME.text;
					bean.dataField = itemME.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == MModuleType.MF.field){//"mf"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemMF:MModuleType in MModuleType.MfModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemMF.text;
					bean.dataField = itemMF.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == KModuleType.KSE.field){//"kse"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemKSE:KModuleType in KModuleType.KseModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemKSE.text;
					bean.dataField = itemKSE.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == KModuleType.KSF.field){//"ksf"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemKSF:KModuleType in KModuleType.KsfModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemKSF.text;
					bean.dataField = itemKSF.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}
			/*else if(type == KModuleType.KLE.field){//"kle"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemKLE:KModuleType in KModuleType.KleModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemKLE.text;
					bean.dataField = itemKLE.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == KModuleType.KLF.field){//"klf"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemKLF:KModuleType in KModuleType.KlfModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemKLF.text;
					bean.dataField = itemKLF.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}*/
			else if(type == PpModuleType.PP.field){//"pp"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemPP:PpModuleType in PpModuleType.PpModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemPP.text;
					bean.dataField = itemPP.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == PpModuleType.T.field){//"t"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemT:PpModuleType in PpModuleType.TModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemT.text;
					bean.dataField = itemT.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}else if(type == PpModuleType.S.field){//"s"
				CommonData.getInstance().dgTypeList.removeAll();
				for each (var itemS:PpModuleType in PpModuleType.SModuleList){
					bean = new DgTypeBean();
					bean.headerText = itemS.text;
					bean.dataField = itemS.field;
					CommonData.getInstance().dgTypeList.addItem(bean);
				}
			}
			
		}
		
		//初始化第一步中左边树的列表
		public function initTreeList():void{
			if(CommonData.getInstance().treeList.length == 0){
				for each (var item:Object in TreeModuleType.treeModuleList){
					CommonData.getInstance().treeList.addItem(item);
				}
			}
		}
		
		public function initCheckBoxList(type:String):void{
			var bean:FactorBean;
			var factorType:FactorType;
			if(type == "" || type == HeModuleType.HE.field || type == HeModuleType.HF.field){//"he、hf"
				factorType = new HFactorType();
				CommonData.getInstance().factorType = factorType;
				CommonData.getInstance().factorList.removeAll();
				for each (var ft1:FactorType in factorType.getFactorList()){
					bean = new FactorBean();
					bean.label = ft1.name;
					bean.id = ft1.attr;
					CommonData.getInstance().factorList.addItem(bean);
				}
			}
			
			/*if(type == FModuleType.FE.field || type == FModuleType.FF.field){//"fe、ff"
				factorType = new FFactorType();
				CommonData.getInstance().factorType = factorType;
				CommonData.getInstance().factorList.removeAll();
				for each (var ft2:FactorType in factorType.getFactorList()){
					bean = new FactorBean();
					bean.label = ft2.name;
					bean.id = ft2.attr;
					CommonData.getInstance().factorList.addItem(bean);
				}
			}*/
			
			if(type == PckModuleType.PCKE.field || type == PckModuleType.PCKF.field){//"pcke,pckf"
				factorType = new PCKFactorType();
				CommonData.getInstance().factorType = factorType;
				CommonData.getInstance().factorList.removeAll();
				for each (var ft3:FactorType in factorType.getFactorList()){
					bean = new FactorBean();
					bean.label = ft3._name;
					bean.id = ft3.attr;
					CommonData.getInstance().factorList.addItem(bean);
				}
			}
			
		/*	if(type == GModuleType.GE.field || type == GModuleType.GF.field){//"pcke,pckf"
				factorType = new GFactorType();
				CommonData.getInstance().factorType = factorType;
				CommonData.getInstance().factorList.removeAll();
				for each (var ft4:FactorType in factorType.getFactorList()){
					bean = new FactorBean();
					bean.label = ft4._name;
					bean.id = ft4.attr;
					CommonData.getInstance().factorList.addItem(bean);
				}
			}*/
			
			if(type == MModuleType.ME.field || type == MModuleType.MF.field){//"me,mf"
				factorType = new MFactorType();
				CommonData.getInstance().factorType = factorType;
				CommonData.getInstance().factorList.removeAll();
				for each (var ft5:FactorType in factorType.getFactorList()){
					bean = new FactorBean();
					bean.label = ft5._name;
					bean.id = ft5.attr;
					CommonData.getInstance().factorList.addItem(bean);
				}
			}
			
			if(type == KModuleType.KSE.field || type == KModuleType.KSF.field){//"kse,ksf"
				factorType = new KsFactorType();
				CommonData.getInstance().factorType = factorType;
				CommonData.getInstance().factorList.removeAll();
				for each (var ft6:FactorType in factorType.getFactorList()){
					bean = new FactorBean();
					bean.label = ft6._name;
					bean.id = ft6.attr;
					CommonData.getInstance().factorList.addItem(bean);
				}
			}
			
		/*	if(type == KModuleType.KLE.field || type == KModuleType.KLF.field){//"kle,klf"
				factorType = new KlFactorType();
				CommonData.getInstance().factorType = factorType;
				CommonData.getInstance().factorList.removeAll();
				for each (var ft7:FactorType in factorType.getFactorList()){
					bean = new FactorBean();
					bean.label = ft7._name;
					bean.id = ft7.attr;
					CommonData.getInstance().factorList.addItem(bean);
				}
			}*/
			
			if(type == PpModuleType.PP.field || type == PpModuleType.T.field){//"pp,t"
				factorType = new PPTFactorType();
				CommonData.getInstance().factorType = factorType;
				CommonData.getInstance().factorList.removeAll();
				for each (var ft8:FactorType in factorType.getFactorList()){
					bean = new FactorBean();
					bean.label = ft8._name;
					bean.id = ft8.attr;
					CommonData.getInstance().factorList.addItem(bean);
				}
			}
			
			if(type == PpModuleType.S.field){//"s"
				factorType = new SFactorType();
				CommonData.getInstance().factorType = factorType;
				CommonData.getInstance().factorList.removeAll();
				for each (var ft9:FactorType in factorType.getFactorList()){
					bean = new FactorBean();
					bean.label = ft9._name;
					bean.id = ft9.attr;
					CommonData.getInstance().factorList.addItem(bean);
				}
			}
		}
	}
}